menutrackeritem: protect against use-after-free
authorChristian Hergert <chergert@redhat.com>
Fri, 24 Jun 2022 21:28:18 +0000 (14:28 -0700)
committerChristian Hergert <chergert@redhat.com>
Fri, 24 Jun 2022 21:30:45 +0000 (14:30 -0700)
commit4d883861b13448869234d3b76fe8ea8a0daba1a2
tree002cf931f2ae02a991989e102105cbdeb0889988
parentf9c0fc4fddc6209efdad838cff0bb457084a1e81
menutrackeritem: protect against use-after-free

With recent updates to GLib, I now see cases where we can hit a state that
has finalized before notify (which will bump the ref count back up). This
is evident in GNOME Text Editor when showing a language submenu from a
popover, and then dismissing the popover and subsequently the tab.

With the previous commit, we at least get a warning like this, which helped
track down the issue.

 Gtk-CRITICAL **: gtk_action_observable_unregister_observer: assertion 'GTK_IS_ACTION_OBSERVABLE (observable)' failed
 GLib-GObject-CRITICAL **: g_object_ref: assertion '!object_already_finalized' failed

This patch fixes both of those criticals.

Fixes #5009
gtk/gtkmenutrackeritem.c